package com.easysoft.framework.chat.service;

import com.easysoft.commons.utils.UUIDUtils;
import com.easysoft.framework.annotation.jdbc.DataSource;
import com.easysoft.framework.beans.Page;
import com.easysoft.framework.chat.mapper.SysChatcontentMapperExtd;
import com.easysoft.framework.chat.model.SysChatcontent;
import com.easysoft.framework.chat.model.SysChatcontentQuery;
import com.easysoft.framework.chat.model.SysChatcontentView;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service("service.SysChatcontentService")
public class SysChatcontentService {
    @Autowired
    @Qualifier("mapper.SysChatcontentMapperExtd")
    private SysChatcontentMapperExtd sysChatcontentMapperExtd;

    @DataSource(DataSource.MASTER)
    public int addSysChatcontent(SysChatcontent entity){
        entity.setId(UUIDUtils.getUUID());
        return sysChatcontentMapperExtd.insertSelective(entity);
    }

    @DataSource(DataSource.MASTER)
    public int deleteSysChatcontent(String id){
        return sysChatcontentMapperExtd.deleteByPrimaryKey(id);
    }

    @DataSource(DataSource.MASTER)
    public int updateSysChatcontent(SysChatcontent entity){
        return sysChatcontentMapperExtd.updateByPrimaryKeySelective(entity);
    }

    @DataSource(DataSource.MASTER)
    public SysChatcontent selectSysChatcontentById(String id){
        return sysChatcontentMapperExtd.selectByPrimaryKey(id);
    }


    @DataSource(DataSource.SLAVE)
    public List<SysChatcontentView> selectSysChatcontentListByPage(SysChatcontentQuery query, Page page){
        int maxRow = sysChatcontentMapperExtd.selectCountSysChatcontent(query);
        page.setMaxRow(maxRow);

        if (maxRow == 0) {
            return new ArrayList<SysChatcontentView>();
        }
        return sysChatcontentMapperExtd.selectSysChatcontentListByPage(query,page);
    }
}
